﻿@page "/commodities"
@inject IPageModelCatche<List< CommodityUserModel>> _pageModelCatche

@inject IHttpService _httpService

<CnGalWebSite.Shared.MasaComponent.Shared.Cards.TitleTip Title="看板娘的小卖铺" />

<CnGalWebSite.Components.Containers.MiniModeContainer>
    <AuthorizeView Roles="Tester">
        <Authorized>
            <MRow>
                <MCol Cols="12" Md="5" Lg="4" Xl="3" Class="mb-4">
                    <CnGalWebSite.Shared.MasaComponent.PC.Commodities.KanbanCard />
                </MCol>
                <MCol Cols="12" Md="7" Lg="8" Xl="9" Class="mb-4">
                    @if (isReady)
                    {
                        <MRow>
                            @foreach (var item in Model)
                            {
                                <MCol Cols="6" Md="6" Lg="4" Xl="3" Class="mb-4">
                                    <CnGalWebSite.Shared.MasaComponent.PC.Commodities.ItemCard Model="item" />
                                </MCol>
                            }
                        </MRow>
                    }
                    else
                    {
                        <CnGalWebSite.Components.Progressings.ProgressingCard Page Fill />
                    }
                </MCol>
            </MRow>
        </Authorized>
        <NotAuthorized>
            <NotAuthorizedTipView NoPermissions="true" />
        </NotAuthorized>
    </AuthorizeView>

</CnGalWebSite.Components.Containers.MiniModeContainer>


@code {
    bool isReady;

    public List<CommodityUserModel> Model { get; set; }

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }


    protected override async Task OnInitializedAsync()
    {
        try
        {
            Model = await _pageModelCatche.GetCache("api/commodities/GetAllCommodities");
            isReady = true;
        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取看板娘的小卖铺商品列表失败");
        }
    }
}
